#!/bin/bash
# futexwait

###SHELLPACK preamble futexwait-bench 1
FUTEXWAIT_ITERATIONS=12
FUTEXWAIT_MAX_THREADS=$NUMCPUS

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam   --min-threads      FUTEXWAIT_MIN_THREADS
###SHELLPACK parseargParam   --max-threads      FUTEXWAIT_MAX_THREADS
###SHELLPACK parseargParam   --iterations	FUTEXWAIT_ITERATIONS
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required futexwait-${VERSION}
###SHELLPACK init_complete

FUTEXWAIT_DIR=$SHELLPACK_SOURCES/futexwait-${VERSION}-installed/performance/
FUTEXWAIT_CMD=${FUTEXWAIT_DIR}/futex_wait

###SHELLPACK threads_large_stride_begin $FUTEXWAIT_MIN_THREADS $FUTEXWAIT_MAX_THREADS $FUTEXWAIT_ITERATIONS
	monitor_pre_hook $LOGDIR_RESULTS $NR_THREADS
	###SHELLPACK iteration_begin $FUTEXWAIT_ITERATIONS
		echo Starting threads $NR_THREADS/$FUTEXWAIT_MAX_THREADS iteration $ITERATION/$FUTEXWAIT_ITERATIONS
		save_rc $FUTEXWAIT_CMD -n $NR_THREADS 2>&1 | \
			tee $LOGDIR_RESULTS/futexwait-${NR_THREADS}-${ITERATION}.log
		recover_rc
		if [ $? -ne 0 ]; then
			die Failed to run futexwait
		fi
	###SHELLPACK iteration_end
	monitor_post_hook $LOGDIR_RESULTS $NR_THREADS
###SHELLPACK threads_stride_end
exit $SHELLPACK_SUCCESS
